<?php

/**
 * This is the model class for table "web_article".
 *
 * The followings are the available columns in table 'web_article':
 * @property integer $id
 * @property string $created
 * @property string $title
 * @property string $contents
 * @property integer $category
 * @property string $sortby
 * @property string $atrtype
 * @property integer $author
 * @property integer $hits
 * @property string $meta
 * @property integer $tags
 * @property string $thumb
 * @property string $links
 * @property string $artfrom
 * @property string $updated
 */
class Article extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Article the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'web_article';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
		array('title,contents','required'),

		array('category, author, hits, tags', 'numerical', 'integerOnly'=>true),
		array('created, title, contents, sortby, atrtype, meta, thumb, links, artfrom, updated', 'safe'),
		// The following rule is used by search().
		// Please remove those attributes that should not be searched.
		array('id, created, title, contents, category, sortby, atrtype, author, hits, meta, tags, thumb, links, artfrom, updated', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
            'cate'=>array(self::BELONGS_TO,'ArticleCategory','category'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '编号',
			'created' => '创建时间',
			'title' => '标题',
			'contents' => '内容',
			'category' => '分类',
			'sortby' => '排序',
			'atrtype' => 'Atrtype',
			'author' => 'Author',
			'hits' => '点击量',
			'meta' => 'Meta',
			'tags' => 'Tags',
			'thumb' => 'Thumb',
			'links' => 'Links',
			'artfrom' => 'Artfrom',
			'updated' => 'Updated',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('contents',$this->contents,true);
		$criteria->compare('category',$this->category);
		$criteria->compare('sortby',$this->sortby,true);
		$criteria->compare('atrtype',$this->atrtype,true);
		$criteria->compare('author',$this->author);
		$criteria->compare('hits',$this->hits);
		$criteria->compare('meta',$this->meta,true);
		$criteria->compare('tags',$this->tags);
		$criteria->compare('thumb',$this->thumb,true);
		$criteria->compare('links',$this->links,true);
		$criteria->compare('artfrom',$this->artfrom,true);
		$criteria->compare('updated',$this->updated,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}